import { Pipe, PipeTransform } from '@angular/core';

@Pipe({ name: 'dateFormat' })

export class DateFormat implements PipeTransform {
  transform(value: any): string {

    let time: string;

    if(!value|| value==''){
        return '';
    }

    if (typeof value == 'string') {

      time = value.slice(0, 10);

    } else {

      let date: Date = new Date(value);

      time = date.getFullYear().toString() + "-" + ((date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : '0' + (date.getMonth() + 1)).toString() + "-" + (date.getDate() > 9 ? date.getDate() : '0' + date.getDate()).toString();
    }

    return time;


  }
}
